home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
varia
/
egebook.lha
/
ege.book
/
1
/
Course2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-04
|
2KB
|
65 lines
#include <stdio.h>
class Teacher {
char *name; // name of teacher
public:
void setName(char *newName){ // member function
name = newName;
};
void print(){
printf("the teachers name is: %s \n", name);
};
};
class Student{
char *name; // name of student
};
class Course {
char *number;
char *time;
Student *students; // NEW: variable number of
// students allowed
public:
Teacher *teacher;
Course(){ // constructor
number = "unassigned"; // with no parameters
time = "TBA";
students = new Student[25]; // create 25 students
};
Course(char *n, char *t, int s = 25){ // constructor
number = n; // with parameters
time = t;
students = new Student[s]; // create a specified
}; // number of students
~Course(){
delete students; // free all students
};
void print(){
printf("Course number: %s, at: %s \n", number, time);
};
};
main() {
Course c1; // constructor is called
// with no parameters
Course c2("COP 4225","MW 1030-1200");
// constructor is called
// with two explicit parameters
c1.print();
c2.print();
Course *c3; // C++ allows to mix
Course *c4; // declarations and statements
c3 = new Course; // constructor is called
// with no parameters
c4 = new Course("COP 6611","TR 1030-1200");
// constructor is called
// with two explicit parameters
c3->print();
c4->print();
}